"""
0:降序（由新到旧）,DESC
1：升序（由旧到新）,ASC
"""

from server.utils.handleFile import getDirCount, getPageGids

table_name = 'activity'
page_size_default = 5
page_default = 1
order_default = 0
order_by_default = 'time'


def is_none(item):
    if item is None or len(item) == 0:
        return True
    return False


# 计算参数
def get_params(page_size, page, order, order_by):
    page_size = page_size_default if is_none(page_size) else int(page_size)
    page_size = page_size_default if page_size < 0 else page_size
    page = page_default if is_none(page) else int(page)
    page = page_default if page < 1 else page
    order = order_default if is_none(order) else int(order)
    order_by = order_by_default if is_none(order_by) else order_by

    # 计算
    order = 'DESC' if order == 0 else 'ASC'
    start_line = (page - 1) * page_size

    return start_line, page_size, order, order_by


# 获取描述信息
def get_activity_all(uid, page_size=page_size_default, page=page_default,
                     order=order_default, order_by=order_by_default):
    # 计算参数
    start_line, page_size, order, order_by = get_params(page_size, page, order, order_by)
    # 获取图id列表
    gids = getPageGids(int(page) - 1, page_size)
    data = [{'gid': gid, 'uid': 'xq'} for gid in gids]
    # 获取总数量
    tol_num = getDirCount("server/database/resource/data")

    return {'tol_num': tol_num, 'data': data}

